/*
 * Copyright 2009-2012 Evun Technology. 
 * 
 * This software is the confidential and proprietary information of
 * Evun Technology. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with evun.cn.
 */
package com.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * 写入
 * 
 * @author Administrator
 *
 */
public class WriteUtils {

	public static void read(String threadName, String FileName) {
		File file = new File("C:/Users/Administrator/Desktop/" + FileName);
		System.out.println("file isExit" + file.isFile());

		List<String> resultList = new ArrayList<String>();
		StringBuilder result = new StringBuilder();
		// A:读取
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));// 构造一个BufferedReader类来读取文件
			String s = null;
			while ((s = br.readLine()) != null) {// 使用readLine方法，一次读一行
				
				if (s.contains(threadName)) {
					// 如果包含
					System.out.println(s);
					resultList.add(s);
					result.append(System.lineSeparator() + s);
				}
			}
			br.close();
			System.out.println(resultList.size());
			// B:写入
			FileWriter fw = new FileWriter("C:/Users/Administrator/Desktop/"
					+ FileName + "1", true);
			BufferedWriter bw = new BufferedWriter(fw);
			for (String string : resultList) {
				bw.write(string+"\r\n");
			}
			bw.close();
            fw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		String fileNmae = "integration.log.2017-06-22";
		String theadName = "querySplitList远程查询钱包结算对账单，结算流水明细  耗时+";
		WriteUtils.read(theadName, fileNmae);
	}

}